package learning.threadlocal;

public class ThreadLocal2 {
	public static void main(String[] args) {
		ThreadL2 t=new ThreadL2();
		Thread t1=new Thread(t, "Tom");
		Thread t2=new Thread(t, "Jerry");
		Thread t3=new Thread(t, "Bob");
		t1.start();
		t2.start();
		t3.start();
//	    t.p();
	}

}
class ThreadL2 implements Runnable{
	
    ThreadLocal<String> t1=new ThreadLocal<String>(){
    	protected String initialValue() {
			return Thread.currentThread().getName();};
    };
    ThreadLocal<String> t2=new ThreadLocal<String>(){
    	protected String initialValue() {
			return Thread.currentThread().getId()+"";};
    };
	@Override
	public  void run() {
//		System.out.println(name+"\t"+id);
		System.out.println(t1.get()+"\t"+t2.get());
		try {
			Thread.sleep(2000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
//		System.out.println(name+"\t"+id);
		System.out.println(t1.get()+"\t"+t2.get());
	}
//	public  void p(){
//		System.out.println(name+"  "+id);
//	}
}